feat(test-utils): Add endoified helper using jsdom in vitest
#33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This will add a
@ocap/test-utils/endoifiedhelper that would make it possible to write tests that would be evaluated after@ocap/shims/endoify.To get this working, I've made other changes that are secondary to the intent of this PR. Those changes are just for staging purposes and will be reverted once the relevant PRs land.
The approach used for testing is to first evaluate the bundled
@ocap/shims/endoifysource text inside a pristineJSDOMinstance, which is then followed by evaluating the function body of the test itself passing to it anendowmentsobject with the respectivevitestcapabilities as its only argument.Simplified code for the
endoifiedhelper:Considerations
Enhancements
The
endoifiedhelper may need to use a differentendoifybundle.The
endoifiedhelperJSDOMcontext may need to be reused.Requirements
The
endoifiedhelper may need to support the use ofJSmodules.JSDOMthat can be addressed usingNODE_OPTIONS=--experimental-vm-modulesalong with linkage logic forvm.SourceTextModule.The
endoifiedhelper maybe need to bundle theshims/dist/endoify.m?json-demand.This would address a limitation with the current
testworkflow:ocap-kernel/.github/workflows/lint-build-test.yml
Lines 125 to 154 in c9cb406
Alternatives
test(extension,streams): Set up browser tests #12 — thanks @grypez
Issues
import.metabetweenJSmodules directly innodeandtsfiles viavitest.JSmodules withJSDOMrequires theThreads
shims: Bundleeventual-sendusing@endo/bundle-source#10eventual-sendusing@endo/bundle-source#22